package b1.mobile.blackberry.dao;

import org.json.me.JSONObject;

import b1.mobile.blackberry.controller.AgentController;
import b1.mobile.blackberry.io.http.ResponseParserHelper;
import b1.mobile.blackberry.io.http.Serviceworker;
import b1.mobile.blackberry.io.http.SoapContentProvider;

public class ActivityDAO extends CommonDAO {
	static String OP_GET = "GetBPActivityDetailByID";
	
	public ActivityDAO(DataAccessDelegate delegate) {
		super(delegate);
	}
	
	public void onGetResult(Serviceworker worker) {
		super.onGetResult(worker);
		
		if(worker.responseCode == 200){
			if(worker.getOperator().equals(OP_GET)){
				parse(worker);
			}
		}
	}

	public void get(String code){
		String[] names = new String[]{"ActivityCode"};
		String[] values = new String[]{code};
		 
		SoapContentProvider soap = new SoapContentProvider(OP_GET, names, values);
		try{
			Serviceworker worker = new Serviceworker(this, AgentController.getServer(), soap);
			new Thread(worker).start();
		} catch (Exception ex){
			ex.printStackTrace();
		}
	}
	
	protected void parse(Serviceworker worker){
		ResponseParserHelper help = new ResponseParserHelper(worker.responseMessage);
		JSONObject json = (JSONObject)help.parse("GetBPActivityDetailByIDResult");
		ActivityEntity ety = new ActivityEntity(json);

		_delegate.onDataReady(worker, ety);
	}
}
